{% extends "_base_nav.html" %}

{% load i18n %}
{% load app_tags %}

{% get_current_language as LANGUAGE_CODE %}

{% block head %}

    <!-- code highlighter -->
    <link href="//cdn.bootcss.com/highlight.js/9.9.0/styles/darcula.min.css" rel="stylesheet">
    <link href="/static/stylesheets/content.css?{% server_start_time %}" media="screen, projection" rel="stylesheet" type="text/css" />

{{ block.super }}
{% endblock %}

{% block content_root %}
{% if settings.ENV != 'production' and settings.ENV != 'staging' %}
{% include '_menu_editor.html' %}

{% endif %}
{{ block.super }}
{% endblock %}


{% block scripts %}
{{ block.super }}
<script src="/static/js/popper.min.js"></script>
<script src="/static/js/permalink-nav.js"></script>
<script src="//cdn.bootcss.com/highlight.js/9.9.0/highlight.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>

<script>
    // Highlight the code, please.
    hljs.initHighlightingOnLoad();
</script>

<script>
    // Use javascript to highlight active links on the side navigation. Since the server does not get the "#" in the
    // request url, we cannot process the command "if request.path == section_link" reliably.
    function highlightSideNavActiveLink(link) {
        var fullPathWithHash = link;
        if (fullPathWithHash == null) {
            fullPathWithHash = location.pathname + location.hash;
        }

        $('#sidebar-nav .chapter').each(function(index) {
            var chapter = $(this);
            chapter.find('.section a[href]').each(function(index) {
                link = $(this);
                address = link.attr('href');
                if (address == fullPathWithHash) {
                    link.addClass('active');
                } else {
                    link.removeClass('active');
                }
            });
        });
    }

    function scrollNavbarBasedOnPage(){
        var tmpAnchor = document.createElement('a');
        tmpAnchor.href = window.location.href;

        var navbar = $('#sidebar-nav'),
            linkSection = $('#sidebar-nav .chapter a[href="' + tmpAnchor.pathname  + '"]').closest('ol');

        if (linkSection.length){
            // -60 because header.
            navbar.scrollTop(linkSection[0].offsetTop - 60);
        }
    }

    (function() {
        $('#sidebar-nav .chapter a[href]').each(function(index) {
            var link = $(this);
            link.click(function(){
                //event.preventDefault();
                highlightSideNavActiveLink(link.attr('href'));
            });
        });

        // NOTE: Temporarily disabling this, because we do not want
        // to see # being used to determine current page from the menu.
        // highlightSideNavActiveLink();
        scrollNavbarBasedOnPage();
    })();

    $( document ).on( "content-updated", function( event, arg1, arg2 ) {
        MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
    });

</script>

{% if allow_search %}
{% include '_search.html' %}
{% endif %}

{% endblock %}
